<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>{{message}}</h1>
        <button @click="changemessage">修改</button>
    </div>
    <script src="https://unpkg.com/vue@next"></script>
    <script>
        //用vue创建app
        const app = Vue.createApp({
            // template: `

            // `,
            data() {
                return {
                    message: "Hello world",
                    info: { name: "ran", age: 18 }
                }
            },
            methods: {
                changemessage() {
                    this.message = "haha",
                        this.info.name="xiaoran"
                        this.info.age=22
                }
            },
            watch: {
                message(newValue, oldValue) {
                    console.log("message变了", newValue, oldValue);
                },

                // info(newValue, oldValue) {
                    //1. 对象类型 拿到的是代理对象
                    // console.log("变了",newValue,oldValue);
                    //2. 拿到原生对象 最初oldValue被后来的newValue覆盖了
                    //1. console.log({...newValue,...oldValue});
                    // console.log(Vue.toRaw(newValue), Vue.toRaw(oldValue));        
                // }

                // 进行深度监听
                info:{
                    handler(newValue,oldValue){
                        console.log("深度侦听：",newValue,oldValue);
                        console.log(newValue===oldValue);
                    },
                    deep:true,
                    // 第一次渲染就执行
                    immdiate:true
                },
                // 第二种写法：
                "info.name":function(newValue,oldValue){
                    console.log("name发生改变:",newValue,oldValue);
                }
            }

        })
        //挂载app
        app.mount("#app")
    </script>

</body>

</html>